home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / BNU22SR1.ZIP / src / binutils.2 / bfd / srec.c < prev    next >
C/C++ Source or Header  |  1993-05-30  |  23KB  |  988 lines

  1. /* BFD back-end for s-record objects.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22. SUBSECTION
  23.     S-Record handling
  24.  
  25. DESCRIPTION
  26.     
  27.     Ordinary S-Records cannot hold anything but addresses and
  28.     data, so that's all that we implement.
  29.    
  30.     The only interesting thing is that S-Records may come out of
  31.     order and there is no header, so an initial scan is required
  32.     to discover the minimum and maximum addresses used to create
  33.     the vma and size of the only section we create.  We
  34.     arbitrarily call this section ".text". 
  35.  
  36.     When bfd_get_section_contents is called the file is read
  37.     again, and this time the data is placed into a bfd_alloc'd
  38.     area.
  39.  
  40.     Any number of sections may be created for output, we save them
  41.     up and output them when it's time to close the bfd.
  42.  
  43.     An s record looks like:
  44.     
  45. EXAMPLE
  46.     S<type><length><address><data><checksum>
  47.     
  48. DESCRIPTION
  49.     Where
  50.     o length
  51.     is the number of bytes following upto the checksum. Note that
  52.     this is not the number of chars following, since it takes two
  53.     chars to represent a byte.
  54.     o type
  55.     is one of:
  56.     0) header record
  57.     1) two byte address data record
  58.     2) three byte address data record
  59.     3) four byte address data record
  60.     7) four byte address termination record
  61.     8) three byte address termination record
  62.     9) two byte address termination record
  63.     
  64.     o address
  65.     is the start address of the data following, or in the case of
  66.     a termination record, the start address of the image
  67.     o data
  68.     is the data.
  69.     o checksum
  70.     is the sum of all the raw byte data in the record, from the length
  71.     upwards, modulo 256 and subtracted from 255.
  72.  
  73.  
  74. SUBSECTION
  75.     Symbol S-Record handling
  76.  
  77. DESCRIPTION
  78.     Some ICE equipment understands an addition to the standard
  79.     S-Record format; symbols and their addresses can be sent
  80.     before the data.
  81.  
  82.     The format of this is:
  83.     ($$ <modulename>
  84.         (<space> <symbol> <address>)*)
  85.     $$
  86.  
  87.     so a short symbol table could look like:
  88.  
  89. EXAMPLE
  90.     $$ flash.x
  91.     $$ flash.c
  92.       _port6 $0
  93.       _delay $4
  94.       _start $14
  95.       _etext $8036
  96.       _edata $8036
  97.        _end $8036
  98.     $$ 
  99.  
  100. DESCRIPTION
  101.     We allow symbols to be anywhere in the data stream - the module names
  102.     are always ignored.
  103.         
  104. */
  105.  
  106. #include "bfd.h"
  107. #include "sysdep.h"
  108. #include "libbfd.h"
  109.  
  110. /* Macros for converting between hex and binary */
  111.  
  112. static CONST char digs[] = "0123456789ABCDEF";
  113.  
  114. static char hex_value[1 + (unsigned char)~0];
  115.  
  116. #define NOT_HEX 20
  117. #define NIBBLE(x) hex_value[(unsigned char)(x)]
  118. #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1]))
  119. #define TOHEX(d, x, ch) \
  120.     d[1] = digs[(x) & 0xf]; \
  121.     d[0] = digs[((x)>>4)&0xf]; \
  122.     ch += ((x) & 0xff);
  123. #define    ISHEX(x)  (hex_value[(unsigned char)(x)] != NOT_HEX)
  124.  
  125.  
  126.  
  127. static void
  128. DEFUN_VOID(srec_init) 
  129. {
  130.     unsigned int i;
  131.     static boolean inited = false;
  132.     
  133.     if (inited == false) 
  134.     {
  135.     
  136.     inited = true;
  137.     
  138.     for (i = 0; i < sizeof (hex_value); i++) 
  139.     {
  140.         hex_value[i] = NOT_HEX;
  141.     }
  142.     
  143.     for (i = 0; i < 10; i++) 
  144.     {
  145.         hex_value[i + '0'] = i;
  146.     
  147.     }
  148.     for (i = 0; i < 6; i++) 
  149.     {
  150.         hex_value[i + 'a'] = i+10;
  151.         hex_value[i + 'A'] = i+10;
  152.     }
  153.     }    
  154. }
  155.  
  156.  
  157. /* The maximum number of bytes on a line is FF */
  158. #define MAXCHUNK 0xff 
  159. /* The number of bytes we fit onto a line on output */
  160. #define CHUNK 21
  161.  
  162. /* We cannot output our srecords as we see them, we have to glue them
  163.    together, this is done in this structure : */
  164.  
  165. struct srec_data_list_struct
  166. {
  167.     unsigned    char *data;
  168.     bfd_vma where;
  169.     bfd_size_type size;
  170.     struct srec_data_list_struct *next;
  171.  
  172.     
  173. } ;
  174. typedef struct srec_data_list_struct srec_data_list_type;
  175.  
  176.  
  177. typedef struct  srec_data_struct
  178. {
  179.     srec_data_list_type *head;    
  180.     unsigned int type;
  181.     
  182.     int done_symbol_read;
  183.     int count;
  184.     asymbol *symbols;
  185.     char *strings;
  186.     int symbol_idx;
  187.     int string_size;
  188.     int string_idx;
  189. } tdata_type;
  190.  
  191.  
  192. /* 
  193.    called once per input S-Record, used to work out vma and size of data.
  194.  */
  195.  
  196. static bfd_vma low,high;
  197.  
  198. static void
  199. size_symbols(abfd, buf, len, val)
  200. bfd *abfd;
  201. char *buf;
  202. int len;
  203. int val;
  204. {
  205.   abfd->symcount ++;
  206.   abfd->tdata.srec_data->string_size  += len + 1;
  207. }
  208.  
  209. static void
  210. fillup_symbols(abfd, buf, len, val)
  211. bfd *abfd;
  212. char *buf;
  213. int len;
  214. int val;
  215. {
  216.   if (!abfd->tdata.srec_data->done_symbol_read)
  217.   {
  218.     asymbol *p;
  219.     if (abfd->tdata.srec_data->symbols == 0)
  220.     {
  221.       abfd->tdata.srec_data->symbols = (asymbol *)bfd_alloc(abfd, abfd->symcount * sizeof(asymbol));
  222.       abfd->tdata.srec_data->strings = (char*)bfd_alloc(abfd, abfd->tdata.srec_data->string_size);
  223.       abfd->tdata.srec_data->symbol_idx = 0;
  224.       abfd->tdata.srec_data->string_idx = 0;
  225.     }
  226.  
  227.     p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
  228.     p->the_bfd = abfd;
  229.     p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
  230.     memcpy((char *)(p->name), buf, len+1);
  231.     abfd->tdata.srec_data->string_idx += len + 1;
  232.     p->value = val;
  233.     p->flags = BSF_EXPORT | BSF_GLOBAL;
  234.     p->section = &bfd_abs_section;
  235.     p->udata = 0;
  236.   }
  237. }
  238. static void
  239. DEFUN(size_srec,(abfd, section, address, raw, length),
  240.       bfd *abfd AND
  241.       asection *section AND
  242.       bfd_vma address AND
  243.       bfd_byte *raw AND
  244.       unsigned int length)
  245. {
  246.   if (address < low)
  247.     low = address;
  248.   if (address + length > high) 
  249.     high = address + length -1;
  250. }
  251.  
  252.  
  253. /*
  254.  called once per input S-Record, copies data from input into bfd_alloc'd area
  255.  */
  256.  
  257. static void
  258. DEFUN(fillup,(abfd, section, address, raw, length),
  259. bfd *abfd AND
  260. asection *section AND
  261. bfd_vma address AND
  262. bfd_byte *raw AND
  263. unsigned int length)
  264. {
  265.     unsigned int i;
  266.     bfd_byte *dst =
  267.      (bfd_byte *)(section->used_by_bfd) + address - section->vma;
  268.     /* length -1 because we don't read in the checksum */
  269.     for (i = 0; i < length -1 ; i++) {
  270.         *dst = HEX(raw);
  271.         dst++;
  272.         raw+=2;
  273.     }
  274. }
  275.  
  276. /* Pass over an S-Record file, calling one of the above functions on each
  277.    record.  */
  278.  
  279. static int white(x)
  280. char x;
  281. {
  282. return (x== ' ' || x == '\t' || x == '\n' || x == '\r');
  283. }
  284. static int
  285. skipwhite(src,abfd)
  286. char *src;
  287. bfd *abfd;
  288. {
  289.   int eof = 0;
  290.   while (white(*src) && !eof)
  291.   {
  292.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  293.   }
  294.   return eof;
  295. }
  296.  
  297. static boolean
  298. DEFUN(srec_mkobject, (abfd), 
  299.       bfd *abfd)
  300. {
  301.   if (abfd->tdata.srec_data == 0) 
  302.   {
  303.     tdata_type *tdata = (tdata_type *)bfd_alloc(abfd,  sizeof(tdata_type));
  304.     abfd->tdata.srec_data = tdata;
  305.     tdata->type = 1;
  306.     tdata->head = (srec_data_list_type *)NULL;
  307.   }
  308.   return true;
  309.     
  310. }
  311.  
  312. static void
  313. DEFUN(pass_over,(abfd, func, symbolfunc, section),
  314.       bfd *abfd AND
  315.       void (*func)() AND
  316.       void (*symbolfunc)() AND
  317.       asection *section)
  318. {
  319.   unsigned int bytes_on_line;
  320.   boolean eof = false;
  321.  
  322.   srec_mkobject(abfd);
  323.   /* To the front of the file */
  324.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  325.   while (eof == false)
  326.   {
  327.     char buffer[MAXCHUNK];
  328.     char *src = buffer;
  329.     char type;
  330.     bfd_vma address = 0;
  331.  
  332.     /* Find first 'S' or $ */
  333.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  334.     switch (*src) 
  335.     {
  336.      default:
  337.       eof = (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  338.       if (eof)  return;
  339.       break;
  340.  
  341.      case '$':
  342.       /* Inside a symbol definition - just ignore the module name */
  343.       while (*src != '\n' && !eof) 
  344.       {
  345.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  346.       }
  347.       break;
  348.  
  349.      case ' ':
  350.       /* spaces - maybe just before a symbol */
  351.       while (*src != '\n' && white(*src)) {
  352.       eof = skipwhite(src, abfd);
  353.  
  354. {
  355.     int val = 0;
  356.     int slen = 0;
  357.     char symbol[MAXCHUNK];
  358.  
  359.     /* get the symbol part */
  360.     while (!eof && !white(*src) && slen < MAXCHUNK)
  361.     {
  362.       symbol[slen++] = *src;
  363.       eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  364.     }
  365.     symbol[slen] = 0;
  366.     eof = skipwhite(src, abfd);
  367.     /* skip the $ for the hex value */
  368.     if (*src == '$') 
  369.     {
  370.       eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  371.     }
  372.  
  373.     /* Scan off the hex number */
  374.     while (isxdigit(*src ))
  375.     {
  376.       val *= 16;
  377.       if (isdigit(*src))
  378.        val += *src - '0';
  379.       else if (isupper(*src)) {
  380.         val += *src - 'A' + 10;
  381.       }
  382.       else {
  383.         val += *src - 'a' + 10;
  384.       }
  385.       eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  386.     }
  387.     symbolfunc(abfd, symbol, slen, val);
  388.       }
  389. }
  390.       break;
  391.      case 'S':
  392.       src++;
  393.  
  394.       /* Fetch the type and the length */
  395.       bfd_read(src, 1, 3, abfd);
  396.  
  397.       type = *src++;
  398.  
  399.       if (!ISHEX (src[0]) || !ISHEX (src[1]))
  400.        break;
  401.  
  402.       bytes_on_line = HEX(src);
  403.  
  404.       if (bytes_on_line > MAXCHUNK/2)
  405.        break;
  406.       src+=2 ;
  407.  
  408.       bfd_read(src, 1 , bytes_on_line * 2, abfd);
  409.  
  410.       switch (type) {
  411.        case '0':
  412.        case '5':
  413.     /* Prologue - ignore */
  414.     break;
  415.        case '3':
  416.     address = HEX(src);
  417.     src+=2;
  418.     bytes_on_line--;
  419.         
  420.        case '2':
  421.     address = HEX(src) | (address<<8) ;
  422.     src+=2;
  423.     bytes_on_line--;
  424.        case '1':
  425.     address = HEX(src) | (address<<8) ;
  426.     src+=2;
  427.     address = HEX(src) | (address<<8) ;
  428.     src+=2;
  429.     bytes_on_line-=2;
  430.     func(abfd,section, address, src, bytes_on_line);
  431.     break;
  432.        default:
  433.     return;
  434.       }
  435.     }
  436.   }
  437.  
  438. }
  439.  
  440. static bfd_target *
  441. object_p(abfd)
  442. bfd *abfd;
  443. {
  444.   asection *section;
  445.   /* We create one section called .text for all the contents, 
  446.      and allocate enough room for the entire file.  */
  447.   
  448.   section =  bfd_make_section(abfd, ".text");
  449.   section->_raw_size = 0;
  450.   section->vma = 0xffffffff;
  451.   low = 0xffffffff;
  452.   high = 0;
  453.   pass_over(abfd, size_srec, size_symbols, section);
  454.   section->_raw_size = high - low;
  455.   section->vma = low;
  456.   section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
  457.  
  458.   if (abfd->symcount)
  459.    abfd->flags |= HAS_SYMS;  
  460.   return abfd->xvec;
  461. }
  462.  
  463. static bfd_target *
  464. DEFUN(srec_object_p, (abfd),
  465.       bfd *abfd)
  466. {
  467.   char b[4];
  468.  
  469.   srec_init();
  470.   
  471.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  472.   bfd_read(b, 1, 4, abfd);
  473.  
  474.   if (b[0] != 'S' || !ISHEX(b[1]) || !ISHEX(b[2]) || !ISHEX(b[3]))
  475.    return (bfd_target*) NULL;
  476.   
  477.   /* We create one section called .text for all the contents, 
  478.      and allocate enough room for the entire file.  */
  479.  
  480.   return object_p(abfd); 
  481. }
  482.  
  483.  
  484. static bfd_target *
  485. DEFUN(symbolsrec_object_p, (abfd),
  486.       bfd *abfd)
  487. {
  488.   char b[4];
  489.  
  490.   srec_init();
  491.   
  492.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  493.   bfd_read(b, 1, 4, abfd);
  494.  
  495.   if (b[0] != '$' || b[1] != '$')
  496.     return (bfd_target*) NULL;
  497.  
  498.   return object_p(abfd);   
  499. }
  500.  
  501.  
  502. static boolean
  503. DEFUN(srec_get_section_contents,(abfd, section, location, offset, count),
  504.       bfd *abfd AND
  505.       asection *section AND
  506.       PTR location AND
  507.       file_ptr offset AND
  508.       bfd_size_type count)
  509. {
  510.     if (section->used_by_bfd == (PTR)NULL) 
  511.     {
  512.     section->used_by_bfd = (PTR)bfd_alloc (abfd, section->_raw_size);
  513.     
  514.     pass_over(abfd, fillup, fillup_symbols, section);
  515.     }
  516.     (void) memcpy((PTR)location,
  517.           (PTR)((char *)(section->used_by_bfd) + offset),
  518.           count);
  519.     return true;
  520. }
  521.       
  522.  
  523.  
  524. boolean
  525. DEFUN(srec_set_arch_mach,(abfd, arch, machine),
  526.       bfd *abfd AND
  527.       enum bfd_architecture arch AND
  528.       unsigned long machine)
  529. {
  530.   return bfd_default_set_arch_mach(abfd, arch, machine);
  531. }
  532.  
  533.  
  534. /* we have to save up all the Srecords for a splurge before output,
  535.    also remember   */
  536.  
  537. static boolean
  538. DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
  539.       bfd *abfd AND
  540.       sec_ptr section AND
  541.       PTR location AND
  542.       file_ptr offset AND
  543.       bfd_size_type bytes_to_do)
  544. {
  545.   tdata_type  *tdata = abfd->tdata.srec_data;
  546.   srec_data_list_type *entry = (srec_data_list_type *)
  547.     bfd_alloc(abfd, sizeof(srec_data_list_type));
  548.  
  549.   if ((section->flags & SEC_ALLOC)
  550.       && (section->flags & SEC_LOAD)) 
  551.     {
  552.       unsigned  char *data = (unsigned char *) bfd_alloc(abfd, bytes_to_do);
  553.       memcpy(data, location, bytes_to_do);
  554.  
  555.       if ((section->lma + offset + bytes_to_do) <= 0xffff)  
  556.     {
  557.  
  558.     }
  559.       else if ((section->lma + offset + bytes_to_do) <= 0xffffff 
  560.            && tdata->type < 2) 
  561.     {
  562.       tdata->type = 2;
  563.     }
  564.       else 
  565.     {
  566.       tdata->type = 3;
  567.     }
  568.  
  569.       entry->data = data;
  570.       entry->where = section->lma + offset;
  571.       entry->size = bytes_to_do;
  572.       entry->next = tdata->head;
  573.       tdata->head = entry;
  574.     }
  575.   return true;    
  576. }
  577.  
  578. /* Write a record of type, of the supplied number of bytes. The
  579.    supplied bytes and length don't have a checksum. That's worked out
  580.    here
  581. */
  582. static
  583. void DEFUN(srec_write_record,(abfd, type, address, data, end),
  584.        bfd *abfd AND
  585.        char type AND
  586.        bfd_vma address AND
  587.        CONST unsigned char *data AND
  588.        CONST unsigned char *end)
  589.  
  590. {
  591.     char buffer[MAXCHUNK];
  592.     
  593.     unsigned int check_sum = 0;
  594.     unsigned CONST char *src = data;
  595.     char *dst =buffer;
  596.     char *length;
  597.     
  598.  
  599.     *dst++ = 'S';
  600.     *dst++ = '0' + type;
  601.  
  602.     length = dst;
  603.     dst+=2;            /* leave room for dst*/
  604.     
  605.     switch (type) 
  606.     {
  607.       case 3:
  608.       case 7:
  609.     TOHEX(dst, (address >> 24), check_sum);
  610.     dst+=2;
  611.       case 8:
  612.       case 2:
  613.     TOHEX(dst, (address >> 16), check_sum);
  614.     dst+=2;
  615.       case 9:
  616.       case 1:
  617.       case 0:
  618.     TOHEX(dst, (address >> 8), check_sum);
  619.     dst+=2;
  620.     TOHEX(dst, (address), check_sum);
  621.     dst+=2;
  622.     break;
  623.  
  624.     }
  625.     for (src = data; src < end; src++) 
  626.     {
  627.     TOHEX(dst, *src, check_sum);
  628.     dst+=2;
  629.     }
  630.  
  631.     /* Fill in the length */
  632.     TOHEX(length, (dst - length)/2, check_sum);
  633.     check_sum &= 0xff;
  634.     check_sum = 255 - check_sum;
  635.     TOHEX(dst, check_sum, check_sum);
  636.     dst+=2;
  637.     
  638.     *dst ++ = '\r';
  639.     *dst ++ = '\n';
  640.     bfd_write((PTR)buffer, 1, dst - buffer , abfd);
  641. }
  642.  
  643.  
  644.  
  645. static void
  646. DEFUN(srec_write_header,(abfd),
  647.       bfd *abfd)
  648. {
  649.     unsigned char buffer[MAXCHUNK];
  650.     unsigned char *dst = buffer;
  651.     unsigned int i;
  652.  
  653.     /* I'll put an arbitary 40 char limit on header size */
  654.     for (i = 0; i < 40 && abfd->filename[i];  i++) 
  655.     {
  656.     *dst++ = abfd->filename[i];
  657.     }
  658.     srec_write_record(abfd,0, 0, buffer, dst);
  659. }
  660.  
  661. static void
  662. DEFUN(srec_write_section,(abfd, tdata, list),
  663.        bfd *abfd AND
  664.        tdata_type *tdata AND
  665.        srec_data_list_type *list)
  666. {
  667.     unsigned int bytes_written = 0;
  668.     unsigned char *location = list->data;
  669.  
  670.     while (bytes_written < list->size)
  671.     {
  672.     bfd_vma address;
  673.     
  674.     unsigned int bytes_this_chunk = list->size - bytes_written;
  675.  
  676.     if (bytes_this_chunk > CHUNK) 
  677.     {
  678.         bytes_this_chunk = CHUNK;
  679.     }
  680.  
  681.     address = list->where +  bytes_written;
  682.  
  683.     srec_write_record(abfd,
  684.               tdata->type,
  685.               address,
  686.               location,
  687.               location + bytes_this_chunk);
  688.  
  689.     bytes_written += bytes_this_chunk;
  690.     location += bytes_this_chunk;
  691.     }
  692.  
  693. }
  694.  
  695. static void
  696. DEFUN(srec_write_terminator,(abfd, tdata),
  697.       bfd *abfd AND
  698.       tdata_type *tdata)
  699. {
  700.     unsigned    char buffer[2];
  701.     
  702.     srec_write_record(abfd, 10 - tdata->type,
  703.               abfd->start_address, buffer, buffer);
  704. }
  705.  
  706.  
  707.       
  708. static void
  709. srec_write_symbols(abfd)
  710. bfd *abfd;
  711. {
  712.   char buffer[MAXCHUNK];
  713.   /* Dump out the symbols of a bfd */
  714.   int i;
  715.   int len = bfd_get_symcount(abfd);
  716.  
  717.   if (len) 
  718.   {
  719.     asymbol **table = bfd_get_outsymbols(abfd);
  720.     sprintf(buffer, "$$ %s\r\n", abfd->filename);
  721.  
  722.     bfd_write(buffer, strlen(buffer), 1, abfd);
  723.  
  724.     for (i = 0; i < len; i++) 
  725.     {
  726.       asymbol *s = table[i];
  727. #if 0
  728.       int len = strlen(s->name);
  729.  
  730.       /* If this symbol has a .[ocs] in it, it's probably a file name
  731.      and we'll output that as the module name */
  732.  
  733.       if (len > 3 && s->name[len-2] == '.') 
  734.       {
  735.     int l;
  736.     sprintf(buffer, "$$ %s\n\r", s->name);
  737.     l = strlen(buffer);
  738.     bfd_write(buffer, l, 1, abfd);
  739.       }
  740.       else
  741. #endif
  742.        if (s->flags & (BSF_GLOBAL | BSF_LOCAL) 
  743.            && (s->flags & BSF_DEBUGGING) == 0
  744.            && s->name[0] != '.'
  745.            && s->name[0] != 't')
  746.       {
  747.     /* Just dump out non debug symbols */
  748.  
  749.     int l;
  750.     sprintf(buffer,"  %s $%x\n\r", s->name, s->value + s->section->lma);
  751.     l = strlen(buffer);
  752.     bfd_write(buffer, l, 1,abfd);
  753.       }
  754.     }
  755.     sprintf(buffer, "$$ \r\n");
  756.     bfd_write(buffer, strlen(buffer), 1, abfd);
  757.   }
  758. }
  759.  
  760. static boolean
  761. internal_srec_write_object_contents(abfd, symbols)
  762.      bfd *abfd;
  763.      int symbols;
  764. {
  765.     int bytes_written;
  766.     tdata_type *tdata = abfd->tdata.srec_data;
  767.     srec_data_list_type *list;
  768.  
  769.     bytes_written = 0;
  770.     
  771.     
  772.     if (symbols)
  773.      srec_write_symbols(abfd);
  774.  
  775.     srec_write_header(abfd);
  776.  
  777.     /* Now wander though all the sections provided and output them */
  778.     list = tdata->head;
  779.  
  780.     while (list != (srec_data_list_type*)NULL) 
  781.     {
  782.     srec_write_section(abfd, tdata, list); 
  783.     list = list->next;
  784.     }
  785.     srec_write_terminator(abfd, tdata);
  786.     return true;
  787. }
  788.  
  789. static boolean
  790. srec_write_object_contents(abfd)
  791.      bfd *abfd;
  792. {
  793.   return internal_srec_write_object_contents(abfd, 0);
  794. }
  795.  
  796. static boolean
  797. symbolsrec_write_object_contents(abfd)
  798.      bfd *abfd;
  799. {
  800.   return internal_srec_write_object_contents(abfd, 1);
  801. }
  802.  
  803. static int 
  804. DEFUN(srec_sizeof_headers,(abfd, exec),
  805.       bfd *abfd AND
  806.       boolean exec)
  807. {
  808. return 0;
  809. }
  810.  
  811. static asymbol *
  812. DEFUN(srec_make_empty_symbol, (abfd),
  813.       bfd*abfd)
  814. {
  815.   asymbol *new=  (asymbol *)bfd_zalloc (abfd, sizeof (asymbol));
  816.   new->the_bfd = abfd;
  817.   return new;
  818. }
  819.  
  820. static unsigned int
  821. srec_get_symtab_upper_bound(abfd)
  822. bfd *abfd;
  823. {
  824.   /* Read in all the info */
  825.   srec_get_section_contents(abfd,abfd->sections,0,0,0);
  826.   return (bfd_get_symcount(abfd) + 1) * (sizeof(asymbol *));
  827. }
  828.  
  829. static unsigned int
  830. DEFUN(srec_get_symtab, (abfd, alocation),
  831.       bfd            *abfd AND
  832.       asymbol       **alocation)
  833. {
  834.   int lim = abfd->symcount;
  835.   int i;
  836.   for (i = 0; i < lim; i++) {
  837.     alocation[i] = abfd->tdata.srec_data->symbols + i;
  838.   }
  839.   alocation[i] = 0;
  840.   return lim;
  841. }
  842.  
  843. void 
  844. DEFUN(srec_print_symbol,(ignore_abfd, afile, symbol, how),
  845.       bfd *ignore_abfd AND
  846.       PTR afile AND
  847.       asymbol *symbol AND
  848.       bfd_print_symbol_type how)
  849. {
  850.   FILE *file = (FILE *)afile;
  851.   switch (how) 
  852.   {
  853.    case bfd_print_symbol_name:
  854.     fprintf (file, "%s", symbol->name);
  855.     break;
  856.    default:
  857.    case bfd_print_symbol_nm:
  858.     bfd_print_symbol_vandf ((PTR) file, symbol);
  859.     fprintf (file, " %-5s %s",
  860.          symbol->section->name,
  861.          symbol->name);
  862.  
  863.   }
  864. }
  865.  
  866. #define FOO PROTO
  867. #define srec_new_section_hook (FOO(boolean, (*), (bfd *, asection *)))bfd_true
  868.  
  869. #define srec_get_reloc_upper_bound (FOO(unsigned int, (*),(bfd*, asection *)))bfd_false
  870. #define srec_canonicalize_reloc (FOO(unsigned int, (*),(bfd*,asection *, arelent **, asymbol **))) bfd_0
  871.  
  872.  
  873.  
  874. #define srec_openr_next_archived_file (FOO(bfd *, (*), (bfd*,bfd*))) bfd_nullvoidptr
  875. #define srec_find_nearest_line (FOO(boolean, (*),(bfd*,asection*,asymbol**,bfd_vma, CONST char**, CONST char**, unsigned int *))) bfd_false
  876. #define srec_generic_stat_arch_elt  (FOO(int, (*), (bfd *,struct stat *))) bfd_0
  877.  
  878.  
  879. #define srec_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
  880. #define srec_core_file_failing_signal (int (*)())bfd_0
  881. #define srec_core_file_matches_executable_p (FOO(boolean, (*),(bfd*, bfd*)))bfd_false
  882. #define srec_slurp_armap bfd_true
  883. #define srec_slurp_extended_name_table bfd_true
  884. #define srec_truncate_arname (void (*)())bfd_nullvoidptr
  885. #define srec_write_armap  (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
  886. #define srec_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
  887. #define    srec_close_and_cleanup    bfd_generic_close_and_cleanup
  888. #define srec_bfd_debug_info_start bfd_void
  889. #define srec_bfd_debug_info_end bfd_void
  890. #define srec_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *,     asection *))) bfd_void
  891. #define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  892. #define srec_bfd_relax_section bfd_generic_relax_section
  893. #define srec_bfd_seclet_link bfd_generic_seclet_link
  894. #define srec_bfd_reloc_type_lookup \
  895.   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
  896. #define srec_bfd_make_debug_symbol \
  897.   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
  898.  
  899. bfd_target srec_vec =
  900. {
  901.     "srec",            /* name */
  902.     bfd_target_srec_flavour,
  903.     true,            /* target byte order */
  904.     true,            /* target headers byte order */
  905.     (HAS_RELOC | EXEC_P |    /* object flags */
  906.      HAS_LINENO | HAS_DEBUG |
  907.      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  908.     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
  909.      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  910.      0,                /* leading underscore */
  911.     ' ',            /* ar_pad_char */
  912.     16,                /* ar_max_namelen */
  913.     1,                /* minimum alignment */
  914.     _do_getb64, _do_getb_signed_64, _do_putb64,
  915.       _do_getb32, _do_getb_signed_32,     _do_putb32,
  916.       _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
  917.     _do_getb64, _do_getb_signed_64, _do_putb64,
  918.       _do_getb32, _do_getb_signed_32,     _do_putb32,
  919.       _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
  920.  
  921.   {
  922.       _bfd_dummy_target,
  923.       srec_object_p,        /* bfd_check_format */
  924.       (struct bfd_target *(*)()) bfd_nullvoidptr,
  925.       (struct bfd_target *(*)())     bfd_nullvoidptr,
  926.   },
  927.   {
  928.       bfd_false,
  929.       srec_mkobject,
  930.       _bfd_generic_mkarchive,
  931.       bfd_false,
  932.   },
  933.   {                /* bfd_write_contents */
  934.       bfd_false,
  935.       srec_write_object_contents,
  936.       _bfd_write_archive_contents,
  937.       bfd_false,
  938.   },
  939.     JUMP_TABLE(srec)
  940.  };
  941.  
  942.  
  943.  
  944. bfd_target symbolsrec_vec =
  945. {
  946.     "symbolsrec",        /* name */
  947.     bfd_target_srec_flavour,
  948.     true,            /* target byte order */
  949.     true,            /* target headers byte order */
  950.     (HAS_RELOC | EXEC_P |    /* object flags */
  951.      HAS_LINENO | HAS_DEBUG |
  952.      HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  953.     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
  954.      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  955.      0,                /* leading underscore */
  956.     ' ',            /* ar_pad_char */
  957.     16,                /* ar_max_namelen */
  958.     1,                /* minimum alignment */
  959.     _do_getb64, _do_getb_signed_64, _do_putb64,
  960.       _do_getb32, _do_getb_signed_32,     _do_putb32,
  961.       _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
  962.     _do_getb64, _do_getb_signed_64, _do_putb64,
  963.       _do_getb32, _do_getb_signed_32,     _do_putb32,
  964.       _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
  965.  
  966.   {
  967.       _bfd_dummy_target,
  968.       symbolsrec_object_p,        /* bfd_check_format */
  969.       (struct bfd_target *(*)()) bfd_nullvoidptr,
  970.       (struct bfd_target *(*)())     bfd_nullvoidptr,
  971.   },
  972.   {
  973.       bfd_false,
  974.       srec_mkobject,
  975.       _bfd_generic_mkarchive,
  976.       bfd_false,
  977.   },
  978.   {                /* bfd_write_contents */
  979.       bfd_false,
  980.       symbolsrec_write_object_contents,
  981.       _bfd_write_archive_contents,
  982.       bfd_false,
  983.   },
  984.     JUMP_TABLE(srec),
  985.     (PTR) 0
  986.  };
  987.  
  988.